layui.use(['form', 'layer', 'table'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table;

    //列表
    const tableIns = table.render({
        elem: '#list',
        url: $.cookie("tempUrl") + 'hSysDoctorAppointmentAllocation/selectList',
        where: {doctorId: $.cookie("doctorId")},
        method: "GET",
        request: {
            pageName: 'pageNum' //页码的参数名称，默认：page
            , limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            , statusCode: 200 //成功的状态码，默认：0
            , msgName: 'httpStatus' //状态信息的字段名称，默认：msg
            , countName: 'totalElements' //数据总数的字段名称，默认：count
            , dataName: 'data' //数据列表的字段名称，默认：data
        },
        cellMinWidth: 95,
        page: true,
        height: "full-25",
        limits: [5, 10, 15, 20, 25],
        limit: 15,
        id: "dataTable",
        toolbar: '#toolbarDemo',
        defaultToolbar: [],
        cols: [[
            {field: 'id', title: 'id', hide: true},
            {field: 'startTime', title: '开始时间', minWidth: 100, align: 'center'},
            {field: 'endTime', title: '结束时间', minWidth: 100, align: 'center'},
            {
                field: 'interrogationStandard', title: '小时号源', minWidth: 100, align: 'center', templet: function (d) {
                    return '每小时' + d.interrogationStandard + '个';
                }
            },
            {field: 'type', title: '周期范围', minWidth: 100, align: 'center'},
            // {
            //     field: 'type', title: '周期范围', width: 100, align: 'center', templet: function (d) {
            //         let split1 = split(d.type);
            //     }
            // },
            {
                field: 'cf', title: '循环配置', width: 100, align: 'center', templet: function (d) {
                    switch (d.cf) {
                        case 1:
                            return '重复';
                        case 2:
                            return '不重复';
                    }
                }
            },
            {
                field: 'state', title: '状态', width: 100, align: 'center', templet: function (d) {
                    switch (d.state) {
                        case 1:
                            return '<input type="checkbox" lay-filter="status" lay-skin="switch" value=' + d.doctorId + ' lay-text="生效|暂停" checked disabled>';
                        case 2:
                            return '<input type="checkbox" lay-filter="status" lay-skin="switch" value=' + d.doctorId + ' lay-text="生效|暂停" disabled>';
                    }
                }
            },
            {title: '操作', width: 145, templet: '#userListBar', fixed: "right", align: "center"}
        ]]
    });

    //头工具栏事件
    table.on('toolbar(test)', function (obj) {
        const checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
            case 'add_btn':
                const index = layui.layer.open({
                    title: "新增号源",
                    type: 2,
                    area: ["540px", "465px"],
                    content: "archives02By02Add.html",
                    maxmin: true,
                    resize: true,
                    shadeClose: true,
                    success: function () {
                        // setTimeout(function () {
                        //     layui.layer.tips('点击此处关闭', '.layui-layer-setwin .layui-layer-close', {
                        //         tips: 3
                        //     });
                        // }, 100)
                    }
                });
                break;
        }
    });

    //列表操作
    table.on('tool(test)', function (obj) {
        const layEvent = obj.event,
            data = obj.data;
        switch (layEvent) {
            case 'edit'://编辑
                $.cookie('tempId', data.id, {path: '/'});
                const index = layui.layer.open({
                    title: "编辑号源",
                    type: 2,
                    area: ["540px", "465px"],
                    content: "archives02By02Upd.html",
                    maxmin: true,
                    resize: true,
                    shadeClose: true
                });
                break;
            case 'del'://删除
                layer.confirm('确定删除此号源？', {icon: 3, title: '提示信息'}, function (index) {
                    $.ajax({
                        url: $.cookie("tempUrl") + "hSysDoctorAppointmentAllocation/deleteById?id=" + data.id,
                        type: "DELETE",
                        success: function (result) {
                            if (result.code === 200) {
                                layer.msg("删除成功");
                                // window.location.href = "informationList.html";
                            } else {
                                layer.alert("删除失败");
                            }
                        }
                    });
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    // tableIns.reload();
                    layer.close(index);
                });
                break;
        }
    });
});
